package svc

import (
	"github.com/hibiken/asynq"
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/zrpc"
	"navi-mumbai/app/rpc/game/client/gamesys"
	"navi-mumbai/app/rpc/stat/client/statsys"
	"navi-mumbai/app/rpc/wallet/client/walletsys"
	"navi-mumbai/app/timer/job/internal/config"
	"navi-mumbai/app/timer/job/internal/redisModel"
)

type ServiceContext struct {
	Config      config.Config
	AsynqServer *asynq.Server

	RedisClient *redis.Redis

	JobRedis *redisModel.JobRedis

	// rpc client
	GameSysRpc   gamesys.GameSys
	WalletSysRpc walletsys.WalletSys
	StatSysRpc   statsys.StatSys
}

func NewServiceContext(c config.Config) *ServiceContext {
	rc := redis.MustNewRedis(c.Redis)
	return &ServiceContext{
		Config:      c,
		RedisClient: rc,
		JobRedis:    redisModel.NewJobRedis(rc),
		AsynqServer: newAsynqServer(c),

		GameSysRpc:   gamesys.NewGameSys(zrpc.MustNewClient(c.GameRpcConf)),
		WalletSysRpc: walletsys.NewWalletSys(zrpc.MustNewClient(c.WalletRpcConf)),
		StatSysRpc:   statsys.NewStatSys(zrpc.MustNewClient(c.StatRpcConf)),
	}
}
